package com.jn.picasso.views;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jn.picasso.R;
import com.jn.picasso.adapter.MovieAdapter;
import com.jn.picasso.base.BaseActivity;
import com.jn.picasso.contract.MovieContract;
import com.jn.picasso.entity.MovieEntity;
import com.jn.picasso.presenter.MoviePresenter;
import com.jn.picasso.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

public class MovieActivity extends BaseActivity implements MovieContract.IMovieView {
    private RecyclerView mRecyclerView;
    private MovieContract.IMoviePresenter mPresenter;
    private MovieAdapter mAdapter;
    private List<MovieEntity.DataDTO> mList;

    @Override
    public int getLayoutId() {
        return R.layout.activity_movie;
    }

    @Override
    public void init() {
        mRecyclerView = findViewById(R.id.recyclerView);
        mPresenter = new MoviePresenter(this);
        LinearLayoutManager linearLayoutManager =
                new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mList = new ArrayList<>();
        mAdapter = new MovieAdapter(mList);
        mRecyclerView.setAdapter(mAdapter);
        mPresenter.getData();
    }

    @Override
    public void showData(MovieEntity movie) {
        if (movie != null && movie.getData() != null) {
            LogUtils.d("asdf", "pic 1 : " + movie.getData().get(0).getPic());
            mList = movie.getData();
            mAdapter.updateData(mList);
        } else {
            showToast("未查到数据，请输入正确单号！");
        }
    }

    @Override
    public void onHttpLoading(boolean loading) {

    }

    @Override
    public void onHttpFail(String... msg) {

    }

    @Override
    public void onHttpTimeout() {

    }

    @Override
    public void onHttpTokenExpiration() {

    }
}